package com.pes_soft.demo.consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 调用依赖的远程服务网关
 *
 * <p>
 * 消费客户端应用启动后，会通过Feign组件到ZooKeeper服务管理中心中查找对应的服务
 * </p>
 * <p>
 * 通常，一个消费客户端会调用A服务、B服务、C服务……<br>
 * 可以将此设计成一个RPC服务网关
 * </p>
 * 
 * @Author 许亮
 * @Create 2017-8-11 10:36:09
 */
@Configuration
public class RpcServiceGateway {
	
	@Autowired
	private ZooKeeperProviderClient zooKeeperProviderClient;
	
	public ZooKeeperProviderClient zooKeeperProviderClient() {
		return zooKeeperProviderClient;
	}

	@FeignClient("spring-cloud-zookeeper-server") // 要调用的服务名，即spring.application.name的值
	public interface ZooKeeperProviderClient {
		@RequestMapping(path="/serverProvider", method=RequestMethod.GET)
		String serverProvider();
		
		@RequestMapping(value="/hello", method=RequestMethod.GET)
		String hello(@RequestParam(value="name") String name);
	}
}